package cn.kgc.cloud.controller;

import cn.kgc.cloud.entity.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @author 课工场
 * @date 2024/1/4
 * @description
 */
@RestController
@RequestMapping("orders")
@Slf4j
public class OrderController {


    @Value("${server.port}")
    private String port;

    @GetMapping("m1")
    public String  method1(){
        // 验证feign请求超时问题
        // try {
        //     Thread.sleep(5000);
        // } catch (InterruptedException e) {
        //     throw new RuntimeException(e);
        // }
        return "invoke orderService ok port:"+port;
    }

    @GetMapping("m2")
    public String  method2(Integer id){

        log.info("--------------order id:{}---------",id);
        return "invoke orderService ok port:"+port+" id="+id;
    }

    @GetMapping("m3/{id}")
    public String  method3(@PathVariable("id") Integer id){

        log.info("--------------order id:{}---------",id);
        return "invoke orderService ok port:"+port+" id="+id;
    }


    @RequestMapping("m4")
    public String  method4(String name, Integer number){

        log.info("--------------order number:{} name:{}---------",number,name);
        return "invoke orderService ok port:"+port+" number="+number+"name="+name;
    }

    @RequestMapping("m5")
    public String  method5(Order order){

        log.info("--------------order = {}---------",order);
        return "invoke orderService ok port:"+port+"--"+order;
    }

    @RequestMapping("m6")
    public String  method6(@RequestBody Order order){

        log.info("--------------order = {}---------",order);
        return "invoke orderService ok port:"+port+"--"+order;
    }

    @RequestMapping("m7")
    public String  method7(Integer[] ids){

        String strIds = Arrays.toString(ids);
        log.info("--------------ids= {}---------",strIds);
        return "invoke orderService ok port:"+port+"--"+strIds;
    }

    // 根据id获取订单信息
    @RequestMapping("m8")
    public Order  method8(Integer id){

        Order order = new Order(id, "xiaomi", 10);
        return order;
    }

    // 获取订单列表
    @RequestMapping("m9")
    public List<Order>  method9(){

        Order order = new Order(20, "xiaomi", 10);
        List<Order> list = Arrays.asList(order, order, order, order);

        return list;
    }


}
